
const fs = require('fs');
const path = require('path');
const { sleep} = require('./Helper')
const MusicPage = require("./MusicPage");
const axios = require('axios');
const Config = require('./Config');

const Download = require('./Download');
const CloudSong = require("./CloudSong");
const BrowserManager = require("./BrowserManager");
const User = require("./User");
const PlayList = require("./PlayList");

const Song = require('./Song');
const Album = require("./Album");


class UserCommand
{
    cookieValue = '';

    /**
     * @type {BrowserManager | null}
     */
    browserManager = null;

    /**
     *
     * @type {User|null}
     */
    user = null;

    /**
     *
     * @type {CloudSong|null}
     */
    cloudSong = null;

    /**
     *
     * @type {PlayList|null}
     */
    playList = null;

    /**
     *
     * @type {Song|null}
     */
    song = null;

    /**
     *
     * @type {Album|null}
     */
    album = null;


    constructor() {

    }

    async init()
    {
        const browserManager = new BrowserManager();
        await browserManager.launchBrowser(false);
        const user = new User();

        this.browserManager = browserManager;
        this.user = user;
        this.cloudSong = new CloudSong(user);
        this.playList = new PlayList(browserManager, user);
        this.song = new Song(browserManager,user)
        this.album = new Album(browserManager);
    }

    async changeSongIdByName(singerId) {
        let data = this.album.getDataBySingerId(singerId);
        if (data === null) {
            await this.album.saveToFile(singerId);
            let data = this.album.getDataBySingerId(singerId);
        }
        await this.cloudSong.changeSongIdByName(data);

    }


    async downSongBySIngerId(singerId){
        let data = this.album.getDataBySingerId(singerId);
        if (data === null) {
            await this.album.saveToFile(singerId);
            let data = this.album.getDataBySingerId(singerId);
        }

        await this.song.downSingerSongs(data);
    }





}

module.exports = UserCommand